<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    ul {
      margin-top: 200px;
      position: relative;
      list-style: none;
      clear: both;
    }
    li {
      float: left;
      height: 100px;
      width: 200px;
      line-height: 100px;
      text-align: center;
      background-color: aquamarine;
    }
    .bgc {
      position: absolute;
      background-color: blueviolet;
      opacity: 0.3;
      left: 0;
      top: 0;
    }
  </style>
  <body>
    <ul>
      <li>郑昊</li>
      <li>李天成</li>
      <li>盘志华</li>
      <li>梁恐爪</li>
      <li class="bgc"></li>
    </ul>
    <script>
      var oLi = document.getElementsByTagName('li');
      var oBg = oLi[oLi.length - 1];
      var timer = null;

      for (var i = 0; i < oLi.length - 1; i++) {
        oLi[i].onmouseenter = function () {
          flex(oBg, this.offsetLeft);
        };
      }

      function flex(dom, target) {
        var speed = 10;
        var a = null;
        timer = setInterval(() => {
          a = (target - dom.offsetLeft) / 7;
          speed += a;
          speed = 0.8 * speed;
          console.log(speed);
          console.log(target - dom.offsetLeft);
          console.log('-------------------');
          if (Math.abs(speed) < 1 && Math.abs(target - dom.offsetLeft < 1)) {
            dom.style.left = target + 'px';
            clearInterval(timer);
          } else {
            dom.style.left = dom.offsetLeft + speed + 'px';
          }
        }, 30);
      }
    </script>
  </body>
</html>
